package com.focusai.efairy.ui.adapter.project;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.focusai.efairy.R;
import com.focusai.efairy.model.project.OnitemTitleClickListener;
import com.focusai.efairy.model.project.ProjectManagerDetail;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by luo_guangwen on 2017/9/8.
 */

public class ProjectMangagerTitleTypeViewBinder extends ItemViewBinder<ProjectManagerDetail.Title, ProjectMangagerTitleTypeViewBinder.ViewHolder> {

    private OnitemTitleClickListener onItemClickListener;
    public ProjectMangagerTitleTypeViewBinder() {
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_project_manager_title, parent, false);
        return  new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final ProjectManagerDetail.Title dataItem) {
        holder.titleText.setText(dataItem.title + " (" + dataItem.count + ")");
        holder.lableText.setText(dataItem.lable);
        if (dataItem.showLable){
            holder.lableText.setVisibility(View.VISIBLE);
            if (onItemClickListener != null){
                holder.titileLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onItemClickListener.onItemClickListener(dataItem.classType);
                    }
                });
            }
        }else {
            holder.lableText.setVisibility(View.GONE);
            holder.titileLayout.setOnClickListener(null);
        }

    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout titileLayout;
        TextView titleText;
        TextView lableText;

        ViewHolder(View itemView) {
            super(itemView);
            titileLayout = (LinearLayout) itemView.findViewById(R.id.llayout_title);
            titleText = (TextView) itemView.findViewById(R.id.text_title);
            lableText = (TextView) itemView.findViewById(R.id.text_project_manager);

        }
    }

    public void setOnItemClickListener(OnitemTitleClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}
